'use strict';

const BaseService = require('./base');

class RoleService extends BaseService {
  get _model() {
    return 'Role';
  }

  async findOne({ id }) {
    const where = { id };
    return this._findOne({ where });
  }

  async create({ name, auth, description }) {
    return this._create({
      name, auth, description,
    });
  }

  async update({ name, auth, description, id }) {
    const where = { id };
    const body = { name, auth, description };
    return this._update({ body, where });
  }

  async destory(id) {
    const where = { id };
    return this._destory({ where });
  }

  async findList({ name, description, pageIndex, pageSize, createdAt, prop, sort }) {
    const where = this.formatWhere({ dim: { name, description }, range: { createdAt } });
    const order = this.formatOrder(prop, sort);
    return this._findList({ pageIndex, pageSize, where, order });
  }

  async findAll() {
    return this._findAll();
  }
}

module.exports = RoleService;
